<%@page import="classes.Subject"%>
<%@page import="classes.SubjectManager"%>
<%@page import="classes.HomeworkManagerStudent"%>
<%@page import="classes.HomeworkManagerLecturer"%>
<%@page import="classes.HomeworkLecturer"%>
<%@page import="java.util.ArrayList"%>
<%@page import="classes.User"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
	<%
		int group = Integer.parseInt(request.getParameter("group"));
		HttpSession s = request.getSession();
		User us = (User) s.getAttribute("user");
		String groupName = us.getSubjectsStudent().get(group)
				.getGroupName();
		out.println(groupName);
	%>
</title>
</head>
<body>
	<h3>
		<%
			int lectorId = us.getSubjectsStudent().get(group).getLectureId();
			String subjectName = us.getSubjectsStudent().get(group)
					.getSubjectName();
			int subId = us.getSubjectsStudent().get(group).getSubId();
			SubjectManager man = (SubjectManager) getServletContext()
					.getAttribute(SubjectManager.SUBJECTMANAGER);
			Subject sub = man.getSubject(subId);
			String lectureName = us.getSubjectsStudent().get(group)
					.getLecturerName();
			out.println("<center>Subject name: " + subjectName + "         		"
					+ ".     Group name: " + groupName + ".     Lecture name: "
					+ "<a href=\"showInfo.jsp?lecturer_id=" + lectorId + "\"" + "target=\"_blank\">>"
					+ lectureName + "</a></center>");
			out.println("<center><a href=\"" + sub.getSyllabusUrl() + "\">"
					+ "Download Syllabus" + "</a></center>");
		%>

	</h3>
	<center>
		<table border="15">
			<tr>
				<th>Homework name</th>
				<th>Start date</th>
				<th>Dead line</th>
				<th>Homework attachment</th>
				<th>Upload</th>
				<th>Mark</th>
				<th>Comment</th>
			</tr>
			<%
				int groupId = us.getSubjectsStudent().get(group).getGroupId();
				int studentId = us.getUserId();
				HomeworkManagerLecturer manager = (HomeworkManagerLecturer) getServletContext()
						.getAttribute(
								HomeworkManagerLecturer.HOMEWORKMANAGERLECTURER);
				HomeworkManagerStudent manager1 = (HomeworkManagerStudent) getServletContext()
						.getAttribute(HomeworkManagerStudent.HOMEWORKMANAGERSTUDENT);
				HomeworkLecturer[] homeworks = manager.getHomeworks(groupId);
				for (int i = 0; i < homeworks.length; i++) {
					out.println("<tr> <td> "
							+ homeworks[i].getHomeworkName()
							+ "</td> <td>"
							+ homeworks[i].getStartTime()
							+ "</td> <td>"
							+ homeworks[i].getEndTime()
							+ "</td> <td>"
							+ "<a href =\""
							+ homeworks[i].getFile()
							+ "\">Download file</a>"
							+ "</td> <td>"
							+ "<a href =\""
							+ manager1.getHomeWorkStudent(studentId,
									homeworks[i].getHomeworkID()).getFile()
							+ "\">Download My File</a>"
							+ "<form action=\"uploadHomework.jsp\" method=\"post\" enctype=\"multipart/form-data\">"
							+ "<input type=\"file\" name=butt value=\"Upload\">"
							+ "<input type=\"hidden\" name=\"group\" value=\""
							+ group
							+ "\">"
							+ "<input type=\"hidden\" name=\"id\" value=\""
							+ homeworks[i].getHomeworkID()
							+ "\">"
							+ "<input type=\"submit\">"
							+ "</form>"
							+ "</td> <td>"
							+ manager1.getHomeWorkStudent(studentId,
									homeworks[i].getHomeworkID()).getMark()
							+ "</td> <td>"
							+ manager1.getHomeWorkStudent(studentId,
									homeworks[i].getHomeworkID()).getComment()
							+ "</td> </tr>");
				}
			%>
		</table>
	</center>
	<a href="studentLogin.jsp">Go Back</a>

</body>
</html>